﻿using System.Threading.Tasks;
using XCI.Core;
using XCI.Sys.Filter;
using XCI.Sys.Model;

namespace XCI.Sys.Service
{
    /// <summary>
    /// 系统日志服务
    /// </summary>
    public class SysLogService
    {
        private const string RootUrl = "/api/sys/log";
        public static SysLogService Instance { get; } = new SysLogService();

        /// <summary>
        /// 根据主键获取操作日志对象
        /// </summary>
        /// <param name="id">日志主键</param>
        public async Task<SysOperateLog> SelectOperateLogByIdAsync(string id)
        {
            return await App.Client.PostAsync<SysOperateLog>($"{RootUrl}/selectOperateLogById", new { id });
        }

        /// <summary>
        /// 查询操作日志分页列表
        /// </summary>
        /// <param name="filter">操作日志过滤条件</param>
        public async Task<PagingList<SysOperateLog>> SelectOperateLogPageListAsync(SysOperateLogFilter filter)
        {
            return await App.Client.PostAsync<PagingList<SysOperateLog>>($"{RootUrl}/selectOperateLogPageList", filter);
        }

        /// <summary>
        /// 根据主键获取单个系统登录日志对象
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>成功返回单个数据对象</returns>
        public async Task<SysLoginLog> SelectLoginLogByIdAsync(string id)
        {
            return await App.Client.PostAsync<SysLoginLog>($"{RootUrl}/selectLoginLogById", new { id });
        }

        /// <summary>
        /// 查询系统登录日志分页列表
        /// </summary>
        /// <param name="filter">过滤器</param>
        public async Task<PagingList<SysLoginLog>> SelectLoginLogPageListAsync(SysLoginLogFilter filter)
        {
            return await App.Client.PostAsync<PagingList<SysLoginLog>>($"{RootUrl}/selectLoginLogPageList", filter);
        }

        /// <summary>
        /// 根据主键获取历史日志对象
        /// </summary>
        /// <param name="id">历史日志主键</param>
        public async Task<SysHistoryLog> SelectHistoryLogByIdAsync(string id)
        {
            return await App.Client.PostAsync<SysHistoryLog>($"{RootUrl}/selectHistoryLogById", new { id });
        }

        /// <summary>
        /// 查询历史日志分页列表
        /// </summary>
        /// <param name="filter">历史日志过滤条件</param>
        public async Task<PagingList<SysHistoryLog>> SelectHistoryLogPageListAsync(SysHistoryLogFilter filter)
        {
            return await App.Client.PostAsync<PagingList<SysHistoryLog>>($"{RootUrl}/selectHistoryLogPageList", filter);
        }

        /// <summary>
        /// 根据主键获取单个系统错误日志对象
        /// </summary>
        /// <param name="id">主键</param>
        public async Task<SysErrorLog> SelectErrorLogByIdAsync(string id)
        {
            return await App.Client.PostAsync<SysErrorLog>($"{RootUrl}/selectErrorLogById", new { id });
        }

        /// <summary>
        /// 查询系统错误日志分页列表
        /// </summary>
        /// <param name="filter">过滤条件</param>
        public async Task<PagingList<SysErrorLog>> SelectErrorLogPageListAsync(SysErrorLogFilter filter)
        {
            return await App.Client.PostAsync<PagingList<SysErrorLog>>($"{RootUrl}/selectErrorLogPageList", filter);
        }

        /// <summary>
        /// 根据主键获取单个系统定时任务日志对象
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>成功返回单个数据对象</returns>
        public async Task<SysJobLog> SelectJobLogByIdAsync(string id)
        {
            return await App.Client.PostAsync<SysJobLog>($"{RootUrl}/selectJobLogById", new { id });
        }

        /// <summary>
        /// 查询系统定时任务日志分页列表
        /// </summary>
        /// <param name="filter">过滤条件</param>
        public async Task<PagingList<SysJobLog>> SelectJobLogPageListAsync(SysJobLogFilter filter)
        {
            return await App.Client.PostAsync<PagingList<SysJobLog>>($"{RootUrl}/selectJobLogPageList", filter);
        }
    }
}
